package com.gao.service;

import com.gao.domain.Blog;
import com.gao.mapper.BlogMapper;
import com.gao.one.OneDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * @author GaoXi
 * @date 2022/3/5 14:02
 */
@Transactional(rollbackFor = Exception.class)
@Service
public class BlogService {

    @Autowired
    private BlogMapper blogMapper;

    /**
     * 测试事务
     *
     * @throws Exception
     */
    public void insertBlog() throws Exception {
        Blog blog = new Blog();
        blog.setName("say bay");
        blogMapper.insertBlog(blog);
        throw new Exception();
    }


    @Autowired
    private OneDao oneDao;


    /**
     * SqlSession方式
     */
    public void testSqlSession() {
        Blog blog = oneDao.selectBlog(1L);
        System.out.println(blog);
    }


}
